﻿BEGIN TRANSACTION
	SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
	SET QUOTED_IDENTIFIER ON
	SET ANSI_NULLS ON
	SET ANSI_PADDING ON
	SET ANSI_WARNINGS ON
	SET ARITHABORT ON
	SET NUMERIC_ROUNDABORT OFF
	SET CONCAT_NULL_YIELDS_NULL ON
	SET XACT_ABORT ON
COMMIT TRANSACTION
GO

IF EXISTS (select * from tempdb..sysobjects where id = OBJECT_ID('tempdb..#ErrorLog')) 
	DROP TABLE #ErrorLog 
CREATE TABLE #ErrorLog 
( pkid [int] IDENTITY(1,1) NOT NULL, errno [int] NOT NULL, errdescr [varchar](100) NULL )
GO

IF @@TRANCOUNT=0 BEGIN TRANSACTION
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[CMSPageTemplate](
	[PageTemplateId] [int] IDENTITY(1,1) NOT NULL,
	[Title] [nvarchar](100) NOT NULL,
	[LanguageId] [varchar](2) NOT NULL,
	[Template] [varchar](50) NOT NULL,
	[Keywords] [nvarchar](255) NULL,
	[Description] [nvarchar](255) NULL,
	[Definition] [ntext] NOT NULL,
	[Tags] [nvarchar](1000) NULL,
	[NoFollow] [bit] NOT NULL,
	[Timestamp] [timestamp] NOT NULL,
 CONSTRAINT [PK_CMSPageTemplate2] PRIMARY KEY CLUSTERED 
(
	[PageTemplateId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
IF @@ERROR<>0 
Begin
	IF @@TRANCOUNT>0 ROLLBACK TRANSACTION
	INSERT INTO #ErrorLog (errno,errdescr) values(@@ERROR,'Failed to add table dbo.CMSPageTemplate')
END
GO

IF @@TRANCOUNT=0 BEGIN TRANSACTION
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[CMSPage] (
	[PageId] [bigint] IDENTITY (1,1) NOT NULL,
	[ParentId] [bigint] NULL,
	[LivePageVersionId] [bigint] NULL,
	[Reference] [nvarchar](20) COLLATE Latin1_General_CI_AS NULL,
	[Timestamp] [timestamp] NOT NULL
) ON [PRIMARY]
GO
IF @@ERROR<>0 
Begin
	IF @@TRANCOUNT>0 ROLLBACK TRANSACTION
	INSERT INTO #ErrorLog (errno,errdescr) values(@@ERROR,'Failed to add table dbo.CMSPage')
END
GO

IF @@TRANCOUNT=0 BEGIN TRANSACTION
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[CMSPageVersion] (
	[PageVersionId] [bigint] IDENTITY (1,1) NOT NULL,
	[PageId] [bigint] NOT NULL,
	[LanguageId] [varchar](2) COLLATE Latin1_General_CI_AS NOT NULL,
	[Order] [int] NOT NULL,
	[UserId] [varchar](40) COLLATE Latin1_General_CI_AS NULL,
	[IsLive] [bit] NOT NULL,
	[DateCreated] [datetime] NOT NULL,
	[Title] [nvarchar](100) COLLATE Latin1_General_CI_AS NOT NULL,
	[Template] [varchar](50) COLLATE Latin1_General_CI_AS NOT NULL,
	[Keywords] [nvarchar](255) COLLATE Latin1_General_CI_AS NULL,
	[Description] [nvarchar](255) COLLATE Latin1_General_CI_AS NULL,
	[Definition] [ntext] COLLATE Latin1_General_CI_AS NOT NULL,
	[Timestamp] [timestamp] NOT NULL,
	[Tags] [nvarchar](1000) NULL,
	[NoFollow] [bit] NOT NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
IF @@ERROR<>0 
Begin
	IF @@TRANCOUNT>0 ROLLBACK TRANSACTION
	INSERT INTO #ErrorLog (errno,errdescr) values(@@ERROR,'Failed to add table dbo.CMSPageVersion')
END
GO

IF @@TRANCOUNT=0 BEGIN TRANSACTION
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[EventLog] (
	[EventId] [bigint] IDENTITY (1,1) NOT NULL,
	[Priority] [int] NOT NULL,
	[Category] [nvarchar](100) COLLATE Latin1_General_CI_AS NOT NULL,
	[Target] [nvarchar](100) COLLATE Latin1_General_CI_AS NOT NULL,
	[Message] [ntext] COLLATE Latin1_General_CI_AS NULL,
	[Method] [nvarchar](200) COLLATE Latin1_General_CI_AS NULL,
	[UserId] [varchar](40) COLLATE Latin1_General_CI_AS NULL,
	[DateCreated] [datetime] NOT NULL,
	[Url] [nvarchar](4000) COLLATE Latin1_General_CI_AS NULL,
	[IPAddress] [nvarchar](40) COLLATE Latin1_General_CI_AS NULL,
	[SessionId] [nvarchar](50) COLLATE Latin1_General_CI_AS NULL,
	[Timestamp] [timestamp] NOT NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
IF @@ERROR<>0 
Begin
	IF @@TRANCOUNT>0 ROLLBACK TRANSACTION
	INSERT INTO #ErrorLog (errno,errdescr) values(@@ERROR,'Failed to add table dbo.EventLog')
END
GO

IF @@TRANCOUNT=0 BEGIN TRANSACTION
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Language] (
	[LanguageId] [varchar](2) COLLATE Latin1_General_CI_AS NOT NULL,
	[Title] [nvarchar](50) COLLATE Latin1_General_CI_AS NOT NULL,
	[IsDefault] [bit] NOT NULL,
	[Timestamp] [timestamp] NOT NULL
) ON [PRIMARY]
GO
IF @@ERROR<>0 
Begin
	IF @@TRANCOUNT>0 ROLLBACK TRANSACTION
	INSERT INTO #ErrorLog (errno,errdescr) values(@@ERROR,'Failed to add table dbo.Language')
END
GO

IF @@TRANCOUNT=0 BEGIN TRANSACTION
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Permission] (
	[PermissionId] [bigint] IDENTITY (1,1) NOT NULL,
	[UserId] [varchar](40) COLLATE Latin1_General_CI_AS NULL,
	[RoleId] [varchar](20) COLLATE Latin1_General_CI_AS NULL,
	[Name] [varchar](40) COLLATE Latin1_General_CI_AS NOT NULL,
	[Value] [varchar](100) COLLATE Latin1_General_CI_AS NOT NULL,
	[Timestamp] [timestamp] NOT NULL
) ON [PRIMARY]
GO
IF @@ERROR<>0 
Begin
	IF @@TRANCOUNT>0 ROLLBACK TRANSACTION
	INSERT INTO #ErrorLog (errno,errdescr) values(@@ERROR,'Failed to add table dbo.Permission')
END
GO

IF @@TRANCOUNT=0 BEGIN TRANSACTION
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Role] (
	[RoleId] [varchar](20) COLLATE Latin1_General_CI_AS NOT NULL,
	[Name] [nvarchar](50) COLLATE Latin1_General_CI_AS NOT NULL,
	[IsDefault] [bit] NOT NULL,
	[Timestamp] [timestamp] NULL
) ON [PRIMARY]
GO
IF @@ERROR<>0 
Begin
	IF @@TRANCOUNT>0 ROLLBACK TRANSACTION
	INSERT INTO #ErrorLog (errno,errdescr) values(@@ERROR,'Failed to add table dbo.Role')
END
GO

IF @@TRANCOUNT=0 BEGIN TRANSACTION
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Translation] (
	[TranslationId] [bigint] IDENTITY (1,1) NOT NULL,
	[Reference] [nvarchar](100) COLLATE Latin1_General_CI_AS NOT NULL,
	[LanguageId] [varchar](2) COLLATE Latin1_General_CI_AS NOT NULL,
	[Translated] [nvarchar](4000) COLLATE Latin1_General_CI_AS NOT NULL,
	[Timestamp] [timestamp] NOT NULL
) ON [PRIMARY]
GO
IF @@ERROR<>0 
Begin
	IF @@TRANCOUNT>0 ROLLBACK TRANSACTION
	INSERT INTO #ErrorLog (errno,errdescr) values(@@ERROR,'Failed to add table dbo.Translation')
END
GO

IF @@TRANCOUNT=0 BEGIN TRANSACTION
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Url] (
	[UrlId] [bigint] IDENTITY (1,1) NOT NULL,
	[PageId] [bigint] NOT NULL,
	[LanguageId] [varchar](2) COLLATE Latin1_General_CI_AS NOT NULL,
	[PageUrl] [varchar](255) COLLATE Latin1_General_CI_AS NOT NULL,
	[Timestamp] [timestamp] NULL
) ON [PRIMARY]
GO
IF @@ERROR<>0 
Begin
	IF @@TRANCOUNT>0 ROLLBACK TRANSACTION
	INSERT INTO #ErrorLog (errno,errdescr) values(@@ERROR,'Failed to add table dbo.Url')
END
GO

IF @@TRANCOUNT=0 BEGIN TRANSACTION
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[User] (
	[UserId] [varchar](40) COLLATE Latin1_General_CI_AS NOT NULL,
	[Password] [varchar](50) COLLATE Latin1_General_CI_AS NULL,
	[Email] [nvarchar](100) COLLATE Latin1_General_CI_AS NULL,
	[Surname] [nvarchar](50) COLLATE Latin1_General_CI_AS NULL,
	[FirstName] [nvarchar](50) COLLATE Latin1_General_CI_AS NULL,
	[IsActive] [bit] NOT NULL,
	[VerificationCode] [nvarchar](2000) COLLATE Latin1_General_CI_AS NOT NULL DEFAULT newid(),
	[Timestamp] [timestamp] NULL
) ON [PRIMARY]
GO
IF @@ERROR<>0 
Begin
	IF @@TRANCOUNT>0 ROLLBACK TRANSACTION
	INSERT INTO #ErrorLog (errno,errdescr) values(@@ERROR,'Failed to add table dbo.User')
END
GO

IF @@TRANCOUNT=0 BEGIN TRANSACTION
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[UserMessage] (
	[MessageId] [bigint] IDENTITY (1,1) NOT NULL,
	[UserId] [varchar](40) COLLATE Latin1_General_CI_AS NOT NULL,
	[Read] [bit] NOT NULL,
	[Category] [nvarchar](30) COLLATE Latin1_General_CI_AS NOT NULL,
	[WorkflowItemId] [bigint] NULL,
	[Tags] [varchar](255) COLLATE Latin1_General_CI_AS NOT NULL,
	[Subject] [nvarchar](100) COLLATE Latin1_General_CI_AS NOT NULL,
	[Body] [ntext] COLLATE Latin1_General_CI_AS NULL,
	[From] [nvarchar](40) COLLATE Latin1_General_CI_AS NULL,
	[FromName] [nvarchar](40) COLLATE Latin1_General_CI_AS NULL,
	[DateCreated] [datetime] NULL,
	[Timestamp] [timestamp] NOT NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
IF @@ERROR<>0 
Begin
	IF @@TRANCOUNT>0 ROLLBACK TRANSACTION
	INSERT INTO #ErrorLog (errno,errdescr) values(@@ERROR,'Failed to add table dbo.UserMessage')
END
GO

IF @@TRANCOUNT=0 BEGIN TRANSACTION
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[UserRole] (
	[UserRoleId] [bigint] IDENTITY (1,1) NOT NULL,
	[UserId] [varchar](40) COLLATE Latin1_General_CI_AS NOT NULL,
	[RoleId] [varchar](20) COLLATE Latin1_General_CI_AS NOT NULL,
	[Timestamp] [timestamp] NULL
) ON [PRIMARY]
GO
IF @@ERROR<>0 
Begin
	IF @@TRANCOUNT>0 ROLLBACK TRANSACTION
	INSERT INTO #ErrorLog (errno,errdescr) values(@@ERROR,'Failed to add table dbo.UserRole')
END
GO

IF @@TRANCOUNT=0 BEGIN TRANSACTION
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[UserToken] (
	[UserTokenId] [varchar](40) COLLATE Latin1_General_CI_AS NOT NULL,
	[UserId] [varchar](40) COLLATE Latin1_General_CI_AS NOT NULL,
	[Timestamp] [timestamp] NULL
) ON [PRIMARY]
GO
IF @@ERROR<>0 
Begin
	IF @@TRANCOUNT>0 ROLLBACK TRANSACTION
	INSERT INTO #ErrorLog (errno,errdescr) values(@@ERROR,'Failed to add table dbo.UserToken')
END
GO

IF @@TRANCOUNT=0 BEGIN TRANSACTION
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[WorkflowComment] (
	[WorkflowCommentId] [bigint] IDENTITY (1,1) NOT NULL,
	[WorkflowItemId] [bigint] NOT NULL,
	[UserId] [varchar](40) COLLATE Latin1_General_CI_AS NOT NULL,
	[DateCreated] [datetime] NOT NULL,
	[Comment] [nvarchar](255) COLLATE Latin1_General_CI_AS NOT NULL,
	[Timestamp] [timestamp] NOT NULL
) ON [PRIMARY]
GO
IF @@ERROR<>0 
Begin
	IF @@TRANCOUNT>0 ROLLBACK TRANSACTION
	INSERT INTO #ErrorLog (errno,errdescr) values(@@ERROR,'Failed to add table dbo.WorkflowComment')
END
GO

IF @@TRANCOUNT=0 BEGIN TRANSACTION
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[WorkflowItem] (
	[WorkflowItemId] [bigint] IDENTITY (1,1) NOT NULL,
	[UserId] [varchar](40) COLLATE Latin1_General_CI_AS NULL,
	[Category] [nvarchar](30) COLLATE Latin1_General_CI_AS NOT NULL,
	[Operation] [varchar](20) COLLATE Latin1_General_CI_AS NOT NULL,
	[Value] [ntext] COLLATE Latin1_General_CI_AS NULL,
	[Status] [int] NOT NULL,
	[TargetType] [varchar](50) COLLATE Latin1_General_CI_AS NOT NULL,
	[TargetName] [varchar](255) COLLATE Latin1_General_CI_AS NOT NULL,
	[RequiredPermissionName] [varchar](20) COLLATE Latin1_General_CI_AS NOT NULL,
	[RequiredPermissionValue] [varchar](100) COLLATE Latin1_General_CI_AS NOT NULL,
	[Timestamp] [timestamp] NOT NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
IF @@ERROR<>0 
Begin
	IF @@TRANCOUNT>0 ROLLBACK TRANSACTION
	INSERT INTO #ErrorLog (errno,errdescr) values(@@ERROR,'Failed to add table dbo.WorkflowItem')
END
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER TABLE [dbo].[Url] ADD 
	CONSTRAINT [DF_CMSPageUrl_Url] DEFAULT ('') FOR [PageUrl]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER TABLE [dbo].[CMSPageVersion] ADD 
	CONSTRAINT [DF_CMSPageVersion_ContentDefinition] DEFAULT (N'') FOR [Definition]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER TABLE [dbo].[CMSPageVersion] ADD 
	CONSTRAINT [DF_CMSPageVersion_Order] DEFAULT ((0)) FOR [Order]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER TABLE [dbo].[CMSPageVersion] ADD 
	CONSTRAINT [DF_CMSPageVersion_Template] DEFAULT ('Default') FOR [Template]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER TABLE [dbo].[CMSPageVersion] ADD 
	CONSTRAINT [DF_CMSPageVersion_Title] DEFAULT (N'') FOR [Title]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER TABLE [dbo].[EventLog] ADD 
	CONSTRAINT [DF_EventLog_DateCreated] DEFAULT (getdate()) FOR [DateCreated]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER TABLE [dbo].[EventLog] ADD 
	CONSTRAINT [DF_EventLog_Priority] DEFAULT ((0)) FOR [Priority]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER TABLE [dbo].[Language] ADD 
	CONSTRAINT [DF_Language_IsDefault] DEFAULT ((0)) FOR [IsDefault]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER TABLE [dbo].[CMSPageVersion] ADD 
	CONSTRAINT [DF_PageVersion_DateCreated] DEFAULT (getdate()) FOR [DateCreated]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER TABLE [dbo].[CMSPageVersion] ADD 
	CONSTRAINT [DF_PageVersion_IsLive] DEFAULT ((0)) FOR [IsLive]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER TABLE [dbo].[Role] ADD 
	CONSTRAINT [DF_Role_Default] DEFAULT ((0)) FOR [IsDefault]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER TABLE [dbo].[Url] ADD 
	CONSTRAINT [DF_Url_LanguageId] DEFAULT (N'en') FOR [LanguageId]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER TABLE [dbo].[UserMessage] ADD 
	CONSTRAINT [DF_UserMessage_Read] DEFAULT ((0)) FOR [Read]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER TABLE [dbo].[UserMessage] ADD 
	CONSTRAINT [DF_UserMessage_Subject] DEFAULT (N'') FOR [Subject]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER TABLE [dbo].[UserMessage] ADD 
	CONSTRAINT [DF_UserMessage_Tags] DEFAULT ('') FOR [Tags]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER TABLE [dbo].[WorkflowItem] ADD 
	CONSTRAINT [DF_WorkflowItem_Status] DEFAULT ((0)) FOR [Status]
GO

IF @@TRANCOUNT=0 BEGIN TRANSACTION
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
if not exists (select * from sys.objects where [name] = N'PK_UserMessage' and [type] = 'PK')
ALTER TABLE [dbo].[UserMessage] ADD 
	CONSTRAINT [PK_UserMessage] PRIMARY KEY CLUSTERED 
	(
		[MessageId]
	) ON [PRIMARY];
GO

IF @@ERROR<>0 
Begin
	IF @@TRANCOUNT>0 ROLLBACK TRANSACTION
	INSERT INTO #ErrorLog (errno,errdescr) values(@@ERROR,'Failed to add primary key dbo.UserMessage.PK_UserMessage')
END
GO
IF @@TRANCOUNT=0 BEGIN TRANSACTION
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
if not exists (select * from sys.objects where [name] = N'PK_User' and [type] = 'PK')
ALTER TABLE [dbo].[User] ADD 
	CONSTRAINT [PK_User] PRIMARY KEY CLUSTERED 
	(
		[UserId]
	) ON [PRIMARY];
GO

IF @@ERROR<>0 
Begin
	IF @@TRANCOUNT>0 ROLLBACK TRANSACTION
	INSERT INTO #ErrorLog (errno,errdescr) values(@@ERROR,'Failed to add primary key dbo.User.PK_User')
END
GO
IF @@TRANCOUNT=0 BEGIN TRANSACTION
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
if not exists (select * from sys.objects where [name] = N'PK_CMSPage' and [type] = 'PK')
ALTER TABLE [dbo].[CMSPage] ADD 
	CONSTRAINT [PK_CMSPage] PRIMARY KEY CLUSTERED 
	(
		[PageId]
	) ON [PRIMARY];
GO

IF @@ERROR<>0 
Begin
	IF @@TRANCOUNT>0 ROLLBACK TRANSACTION
	INSERT INTO #ErrorLog (errno,errdescr) values(@@ERROR,'Failed to add primary key dbo.CMSPage.PK_CMSPage')
END
GO
IF @@TRANCOUNT=0 BEGIN TRANSACTION
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
if not exists (select * from sys.objects where [name] = N'PK_UserToken' and [type] = 'PK')
ALTER TABLE [dbo].[UserToken] ADD 
	CONSTRAINT [PK_UserToken] PRIMARY KEY CLUSTERED 
	(
		[UserTokenId]
	) ON [PRIMARY];
GO

IF @@ERROR<>0 
Begin
	IF @@TRANCOUNT>0 ROLLBACK TRANSACTION
	INSERT INTO #ErrorLog (errno,errdescr) values(@@ERROR,'Failed to add primary key dbo.UserToken.PK_UserToken')
END
GO
IF @@TRANCOUNT=0 BEGIN TRANSACTION
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
if not exists (select * from sys.objects where [name] = N'PK_UserRole' and [type] = 'PK')
ALTER TABLE [dbo].[UserRole] ADD 
	CONSTRAINT [PK_UserRole] PRIMARY KEY CLUSTERED 
	(
		[UserRoleId]
	) ON [PRIMARY];
GO

IF @@ERROR<>0 
Begin
	IF @@TRANCOUNT>0 ROLLBACK TRANSACTION
	INSERT INTO #ErrorLog (errno,errdescr) values(@@ERROR,'Failed to add primary key dbo.UserRole.PK_UserRole')
END
GO
IF @@TRANCOUNT=0 BEGIN TRANSACTION
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
if not exists (select * from sys.objects where [name] = N'PK_WorkflowItem' and [type] = 'PK')
ALTER TABLE [dbo].[WorkflowItem] ADD 
	CONSTRAINT [PK_WorkflowItem] PRIMARY KEY CLUSTERED 
	(
		[WorkflowItemId]
	) ON [PRIMARY];
GO

IF @@ERROR<>0 
Begin
	IF @@TRANCOUNT>0 ROLLBACK TRANSACTION
	INSERT INTO #ErrorLog (errno,errdescr) values(@@ERROR,'Failed to add primary key dbo.WorkflowItem.PK_WorkflowItem')
END
GO
IF @@TRANCOUNT=0 BEGIN TRANSACTION
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
if not exists (select * from sys.objects where [name] = N'PK_WorkflowComment' and [type] = 'PK')
ALTER TABLE [dbo].[WorkflowComment] ADD 
	CONSTRAINT [PK_WorkflowComment] PRIMARY KEY CLUSTERED 
	(
		[WorkflowCommentId]
	) ON [PRIMARY];
GO

IF @@ERROR<>0 
Begin
	IF @@TRANCOUNT>0 ROLLBACK TRANSACTION
	INSERT INTO #ErrorLog (errno,errdescr) values(@@ERROR,'Failed to add primary key dbo.WorkflowComment.PK_WorkflowComment')
END
GO
IF @@TRANCOUNT=0 BEGIN TRANSACTION
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
if not exists (select * from sys.objects where [name] = N'PK_PageVersion' and [type] = 'PK')
ALTER TABLE [dbo].[CMSPageVersion] ADD 
	CONSTRAINT [PK_PageVersion] PRIMARY KEY CLUSTERED 
	(
		[PageVersionId]
	) ON [PRIMARY];
GO

IF @@ERROR<>0 
Begin
	IF @@TRANCOUNT>0 ROLLBACK TRANSACTION
	INSERT INTO #ErrorLog (errno,errdescr) values(@@ERROR,'Failed to add primary key dbo.CMSPageVersion.PK_PageVersion')
END
GO
IF @@TRANCOUNT=0 BEGIN TRANSACTION
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
if not exists (select * from sys.objects where [name] = N'PK_Role' and [type] = 'PK')
ALTER TABLE [dbo].[Role] ADD 
	CONSTRAINT [PK_Role] PRIMARY KEY CLUSTERED 
	(
		[RoleId]
	) ON [PRIMARY];
GO

IF @@ERROR<>0 
Begin
	IF @@TRANCOUNT>0 ROLLBACK TRANSACTION
	INSERT INTO #ErrorLog (errno,errdescr) values(@@ERROR,'Failed to add primary key dbo.Role.PK_Role')
END
GO
IF @@TRANCOUNT=0 BEGIN TRANSACTION
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
if not exists (select * from sys.objects where [name] = N'PK_Permission' and [type] = 'PK')
ALTER TABLE [dbo].[Permission] ADD 
	CONSTRAINT [PK_Permission] PRIMARY KEY CLUSTERED 
	(
		[PermissionId]
	) ON [PRIMARY];
GO

IF @@ERROR<>0 
Begin
	IF @@TRANCOUNT>0 ROLLBACK TRANSACTION
	INSERT INTO #ErrorLog (errno,errdescr) values(@@ERROR,'Failed to add primary key dbo.Permission.PK_Permission')
END
GO
IF @@TRANCOUNT=0 BEGIN TRANSACTION
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
if not exists (select * from sys.objects where [name] = N'PK_Translation' and [type] = 'PK')
ALTER TABLE [dbo].[Translation] ADD 
	CONSTRAINT [PK_Translation] PRIMARY KEY CLUSTERED 
	(
		[TranslationId]
	) ON [PRIMARY];
GO

IF @@ERROR<>0 
Begin
	IF @@TRANCOUNT>0 ROLLBACK TRANSACTION
	INSERT INTO #ErrorLog (errno,errdescr) values(@@ERROR,'Failed to add primary key dbo.Translation.PK_Translation')
END
GO
IF @@TRANCOUNT=0 BEGIN TRANSACTION
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
if not exists (select * from sys.objects where [name] = N'PK_CMSPageUrl' and [type] = 'PK')
ALTER TABLE [dbo].[Url] ADD 
	CONSTRAINT [PK_CMSPageUrl] PRIMARY KEY CLUSTERED 
	(
		[UrlId]
	) ON [PRIMARY];
GO

IF @@ERROR<>0 
Begin
	IF @@TRANCOUNT>0 ROLLBACK TRANSACTION
	INSERT INTO #ErrorLog (errno,errdescr) values(@@ERROR,'Failed to add primary key dbo.Url.PK_CMSPageUrl')
END
GO
IF @@TRANCOUNT=0 BEGIN TRANSACTION
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
if not exists (select * from sys.objects where [name] = N'PK_Language' and [type] = 'PK')
ALTER TABLE [dbo].[Language] ADD 
	CONSTRAINT [PK_Language] PRIMARY KEY CLUSTERED 
	(
		[LanguageId]
	) ON [PRIMARY];
GO

IF @@ERROR<>0 
Begin
	IF @@TRANCOUNT>0 ROLLBACK TRANSACTION
	INSERT INTO #ErrorLog (errno,errdescr) values(@@ERROR,'Failed to add primary key dbo.Language.PK_Language')
END
GO
IF @@TRANCOUNT=0 BEGIN TRANSACTION
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
if not exists (select * from sys.objects where [name] = N'PK_EventLog' and [type] = 'PK')
ALTER TABLE [dbo].[EventLog] ADD 
	CONSTRAINT [PK_EventLog] PRIMARY KEY CLUSTERED 
	(
		[EventId]
	) ON [PRIMARY];
GO

IF @@ERROR<>0 
Begin
	IF @@TRANCOUNT>0 ROLLBACK TRANSACTION
	INSERT INTO #ErrorLog (errno,errdescr) values(@@ERROR,'Failed to add primary key dbo.EventLog.PK_EventLog')
END
GO
IF @@TRANCOUNT=0 BEGIN TRANSACTION
GO
if not exists (select * from sys.indexes where [name] = N'IX_CMSPage' and [object_id] = object_id(N'[dbo].[CMSPage]')) 
CREATE INDEX [IX_CMSPage] ON [dbo].[CMSPage] ([ParentId]) ON [PRIMARY];
GO
IF @@ERROR<>0 
Begin
	IF @@TRANCOUNT>0 ROLLBACK TRANSACTION
	INSERT INTO #ErrorLog (errno,errdescr) values(@@ERROR,'Failed to add index dbo.CMSPage.IX_CMSPage')
END
GO

IF @@TRANCOUNT=0 BEGIN TRANSACTION
GO
if not exists (select * from sys.indexes where [name] = N'IX_UserMessage' and [object_id] = object_id(N'[dbo].[UserMessage]')) 
CREATE INDEX [IX_UserMessage] ON [dbo].[UserMessage] ([Category]) ON [PRIMARY];
GO
IF @@ERROR<>0 
Begin
	IF @@TRANCOUNT>0 ROLLBACK TRANSACTION
	INSERT INTO #ErrorLog (errno,errdescr) values(@@ERROR,'Failed to add index dbo.UserMessage.IX_UserMessage')
END
GO

IF @@TRANCOUNT=0 BEGIN TRANSACTION
GO
if not exists (select * from sys.indexes where [name] = N'IX_UserMessage_1' and [object_id] = object_id(N'[dbo].[UserMessage]')) 
CREATE INDEX [IX_UserMessage_1] ON [dbo].[UserMessage] ([Tags]) ON [PRIMARY];
GO
IF @@ERROR<>0 
Begin
	IF @@TRANCOUNT>0 ROLLBACK TRANSACTION
	INSERT INTO #ErrorLog (errno,errdescr) values(@@ERROR,'Failed to add index dbo.UserMessage.IX_UserMessage_1')
END
GO

IF @@TRANCOUNT=0 BEGIN TRANSACTION
GO
if not exists (select * from sys.indexes where [name] = N'IX_UserMessage_2' and [object_id] = object_id(N'[dbo].[UserMessage]')) 
CREATE INDEX [IX_UserMessage_2] ON [dbo].[UserMessage] ([UserId]) ON [PRIMARY];
GO
IF @@ERROR<>0 
Begin
	IF @@TRANCOUNT>0 ROLLBACK TRANSACTION
	INSERT INTO #ErrorLog (errno,errdescr) values(@@ERROR,'Failed to add index dbo.UserMessage.IX_UserMessage_2')
END
GO

IF @@TRANCOUNT=0 BEGIN TRANSACTION
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
if not exists (select * from sys.objects where [name] = N'FK_WorkflowItem_User' and [type] = 'F')
ALTER TABLE [dbo].[WorkflowItem] ADD 
	CONSTRAINT [FK_WorkflowItem_User] FOREIGN KEY 
	(
		[UserId]
	)REFERENCES [dbo].[User](
		[UserId]
	)ON UPDATE NO ACTION ON DELETE NO ACTION 
GO
IF @@ERROR<>0 
Begin
	IF @@TRANCOUNT>0 ROLLBACK TRANSACTION
	INSERT INTO #ErrorLog (errno,errdescr) values(@@ERROR,'Failed to add foreign key dbo.WorkflowItem.FK_WorkflowItem_User')
END
GO
IF @@TRANCOUNT=0 BEGIN TRANSACTION
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
if not exists (select * from sys.objects where [name] = N'FK_CMSPageVersion_CMSPageVersion' and [type] = 'F')
ALTER TABLE [dbo].[CMSPageVersion] ADD 
	CONSTRAINT [FK_CMSPageVersion_CMSPageVersion] FOREIGN KEY 
	(
		[PageId]
	)REFERENCES [dbo].[CMSPage](
		[PageId]
	)ON UPDATE NO ACTION ON DELETE NO ACTION 
GO
IF @@ERROR<>0 
Begin
	IF @@TRANCOUNT>0 ROLLBACK TRANSACTION
	INSERT INTO #ErrorLog (errno,errdescr) values(@@ERROR,'Failed to add foreign key dbo.CMSPageVersion.FK_CMSPageVersion_CMSPageVersion')
END
GO
IF @@TRANCOUNT=0 BEGIN TRANSACTION
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
if not exists (select * from sys.objects where [name] = N'FK_CMSPageVersion_Language' and [type] = 'F')
ALTER TABLE [dbo].[CMSPageVersion] ADD 
	CONSTRAINT [FK_CMSPageVersion_Language] FOREIGN KEY 
	(
		[LanguageId]
	)REFERENCES [dbo].[Language](
		[LanguageId]
	)ON UPDATE NO ACTION ON DELETE NO ACTION 
GO
IF @@ERROR<>0 
Begin
	IF @@TRANCOUNT>0 ROLLBACK TRANSACTION
	INSERT INTO #ErrorLog (errno,errdescr) values(@@ERROR,'Failed to add foreign key dbo.CMSPageVersion.FK_CMSPageVersion_Language')
END
GO
IF @@TRANCOUNT=0 BEGIN TRANSACTION
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
if not exists (select * from sys.objects where [name] = N'FK_CMSPageVersion_User' and [type] = 'F')
ALTER TABLE [dbo].[CMSPageVersion] ADD 
	CONSTRAINT [FK_CMSPageVersion_User] FOREIGN KEY 
	(
		[UserId]
	)REFERENCES [dbo].[User](
		[UserId]
	)ON UPDATE NO ACTION ON DELETE NO ACTION 
GO
IF @@ERROR<>0 
Begin
	IF @@TRANCOUNT>0 ROLLBACK TRANSACTION
	INSERT INTO #ErrorLog (errno,errdescr) values(@@ERROR,'Failed to add foreign key dbo.CMSPageVersion.FK_CMSPageVersion_User')
END
GO
IF @@TRANCOUNT=0 BEGIN TRANSACTION
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
if not exists (select * from sys.objects where [name] = N'FK_WorkflowComment_WorkflowComment' and [type] = 'F')
ALTER TABLE [dbo].[WorkflowComment] ADD 
	CONSTRAINT [FK_WorkflowComment_WorkflowComment] FOREIGN KEY 
	(
		[UserId]
	)REFERENCES [dbo].[User](
		[UserId]
	)ON UPDATE NO ACTION ON DELETE NO ACTION 
GO
IF @@ERROR<>0 
Begin
	IF @@TRANCOUNT>0 ROLLBACK TRANSACTION
	INSERT INTO #ErrorLog (errno,errdescr) values(@@ERROR,'Failed to add foreign key dbo.WorkflowComment.FK_WorkflowComment_WorkflowComment')
END
GO
IF @@TRANCOUNT=0 BEGIN TRANSACTION
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
if not exists (select * from sys.objects where [name] = N'FK_WorkflowComment_WorkflowItem' and [type] = 'F')
ALTER TABLE [dbo].[WorkflowComment] ADD 
	CONSTRAINT [FK_WorkflowComment_WorkflowItem] FOREIGN KEY 
	(
		[WorkflowItemId]
	)REFERENCES [dbo].[WorkflowItem](
		[WorkflowItemId]
	)ON UPDATE NO ACTION ON DELETE NO ACTION 
GO
IF @@ERROR<>0 
Begin
	IF @@TRANCOUNT>0 ROLLBACK TRANSACTION
	INSERT INTO #ErrorLog (errno,errdescr) values(@@ERROR,'Failed to add foreign key dbo.WorkflowComment.FK_WorkflowComment_WorkflowItem')
END
GO
IF @@TRANCOUNT=0 BEGIN TRANSACTION
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
if not exists (select * from sys.objects where [name] = N'FK_UserToken_UserToken' and [type] = 'F')
ALTER TABLE [dbo].[UserToken] ADD 
	CONSTRAINT [FK_UserToken_UserToken] FOREIGN KEY 
	(
		[UserId]
	)REFERENCES [dbo].[User](
		[UserId]
	)ON UPDATE NO ACTION ON DELETE NO ACTION 
GO
IF @@ERROR<>0 
Begin
	IF @@TRANCOUNT>0 ROLLBACK TRANSACTION
	INSERT INTO #ErrorLog (errno,errdescr) values(@@ERROR,'Failed to add foreign key dbo.UserToken.FK_UserToken_UserToken')
END
GO
IF @@TRANCOUNT=0 BEGIN TRANSACTION
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
if not exists (select * from sys.objects where [name] = N'FK_UserMessage_WorkflowItem' and [type] = 'F')
ALTER TABLE [dbo].[UserMessage] ADD 
	CONSTRAINT [FK_UserMessage_WorkflowItem] FOREIGN KEY 
	(
		[WorkflowItemId]
	)REFERENCES [dbo].[WorkflowItem](
		[WorkflowItemId]
	)ON UPDATE NO ACTION ON DELETE NO ACTION 
GO
IF @@ERROR<>0 
Begin
	IF @@TRANCOUNT>0 ROLLBACK TRANSACTION
	INSERT INTO #ErrorLog (errno,errdescr) values(@@ERROR,'Failed to add foreign key dbo.UserMessage.FK_UserMessage_WorkflowItem')
END
GO
IF @@TRANCOUNT=0 BEGIN TRANSACTION
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
if not exists (select * from sys.objects where [name] = N'FK_Translation_Language' and [type] = 'F')
ALTER TABLE [dbo].[Translation] ADD 
	CONSTRAINT [FK_Translation_Language] FOREIGN KEY 
	(
		[LanguageId]
	)REFERENCES [dbo].[Language](
		[LanguageId]
	)ON UPDATE NO ACTION ON DELETE NO ACTION 
GO
IF @@ERROR<>0 
Begin
	IF @@TRANCOUNT>0 ROLLBACK TRANSACTION
	INSERT INTO #ErrorLog (errno,errdescr) values(@@ERROR,'Failed to add foreign key dbo.Translation.FK_Translation_Language')
END
GO
IF @@TRANCOUNT=0 BEGIN TRANSACTION
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
if not exists (select * from sys.objects where [name] = N'FK_Permission_Permission' and [type] = 'F')
ALTER TABLE [dbo].[Permission] ADD 
	CONSTRAINT [FK_Permission_Permission] FOREIGN KEY 
	(
		[UserId]
	)REFERENCES [dbo].[User](
		[UserId]
	)ON UPDATE NO ACTION ON DELETE NO ACTION 
GO
IF @@ERROR<>0 
Begin
	IF @@TRANCOUNT>0 ROLLBACK TRANSACTION
	INSERT INTO #ErrorLog (errno,errdescr) values(@@ERROR,'Failed to add foreign key dbo.Permission.FK_Permission_Permission')
END
GO
IF @@TRANCOUNT=0 BEGIN TRANSACTION
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
if not exists (select * from sys.objects where [name] = N'FK_Permission_Role' and [type] = 'F')
ALTER TABLE [dbo].[Permission] ADD 
	CONSTRAINT [FK_Permission_Role] FOREIGN KEY 
	(
		[RoleId]
	)REFERENCES [dbo].[Role](
		[RoleId]
	)ON UPDATE NO ACTION ON DELETE NO ACTION 
GO
IF @@ERROR<>0 
Begin
	IF @@TRANCOUNT>0 ROLLBACK TRANSACTION
	INSERT INTO #ErrorLog (errno,errdescr) values(@@ERROR,'Failed to add foreign key dbo.Permission.FK_Permission_Role')
END
GO
IF @@TRANCOUNT=0 BEGIN TRANSACTION
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
if not exists (select * from sys.objects where [name] = N'FK_UserRole_Role' and [type] = 'F')
ALTER TABLE [dbo].[UserRole] ADD 
	CONSTRAINT [FK_UserRole_Role] FOREIGN KEY 
	(
		[RoleId]
	)REFERENCES [dbo].[Role](
		[RoleId]
	)ON UPDATE NO ACTION ON DELETE NO ACTION 
GO
IF @@ERROR<>0 
Begin
	IF @@TRANCOUNT>0 ROLLBACK TRANSACTION
	INSERT INTO #ErrorLog (errno,errdescr) values(@@ERROR,'Failed to add foreign key dbo.UserRole.FK_UserRole_Role')
END
GO
IF @@TRANCOUNT=0 BEGIN TRANSACTION
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
if not exists (select * from sys.objects where [name] = N'FK_UserRole_UserRole' and [type] = 'F')
ALTER TABLE [dbo].[UserRole] ADD 
	CONSTRAINT [FK_UserRole_UserRole] FOREIGN KEY 
	(
		[UserId]
	)REFERENCES [dbo].[User](
		[UserId]
	)ON UPDATE NO ACTION ON DELETE NO ACTION 
GO
IF @@ERROR<>0 
Begin
	IF @@TRANCOUNT>0 ROLLBACK TRANSACTION
	INSERT INTO #ErrorLog (errno,errdescr) values(@@ERROR,'Failed to add foreign key dbo.UserRole.FK_UserRole_UserRole')
END
GO
IF @@TRANCOUNT=0 BEGIN TRANSACTION
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
if not exists (select * from sys.objects where [name] = N'FK_CMSPageUrl_CMSPage' and [type] = 'F')
ALTER TABLE [dbo].[Url] ADD 
	CONSTRAINT [FK_CMSPageUrl_CMSPage] FOREIGN KEY 
	(
		[PageId]
	)REFERENCES [dbo].[CMSPage](
		[PageId]
	)ON UPDATE NO ACTION ON DELETE NO ACTION 
GO
IF @@ERROR<>0 
Begin
	IF @@TRANCOUNT>0 ROLLBACK TRANSACTION
	INSERT INTO #ErrorLog (errno,errdescr) values(@@ERROR,'Failed to add foreign key dbo.Url.FK_CMSPageUrl_CMSPage')
END
GO
IF @@TRANCOUNT=0 BEGIN TRANSACTION
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
if not exists (select * from sys.objects where [name] = N'FK_Url_Language' and [type] = 'F')
ALTER TABLE [dbo].[Url] ADD 
	CONSTRAINT [FK_Url_Language] FOREIGN KEY 
	(
		[LanguageId]
	)REFERENCES [dbo].[Language](
		[LanguageId]
	)ON UPDATE NO ACTION ON DELETE NO ACTION 
GO
IF @@ERROR<>0 
Begin
	IF @@TRANCOUNT>0 ROLLBACK TRANSACTION
	INSERT INTO #ErrorLog (errno,errdescr) values(@@ERROR,'Failed to add foreign key dbo.Url.FK_Url_Language')
END
GO
IF @@TRANCOUNT=0 BEGIN TRANSACTION

GO
IF EXISTS (Select * from #ErrorLog)
BEGIN
	IF @@TRANCOUNT>0 ROLLBACK TRANSACTION
END
ELSE
BEGIN
	IF @@TRANCOUNT>0 COMMIT TRANSACTION
END
IF EXISTS (Select * from #ErrorLog)
BEGIN
	Print 'Database synchronization script failed'
	GOTO QuitWithErrors
END
ELSE
BEGIN
	Print 'Database synchronization completed successfully'
END



QuitWithErrors:

GO

INSERT [dbo].[Language] ([LanguageId], [Title], [IsDefault]) VALUES (N'en', N'English', 1)

SET IDENTITY_INSERT [dbo].[CMSPage] ON
INSERT [dbo].[CMSPage] ([PageId], [ParentId], [LivePageVersionId], [Reference]) VALUES (1, NULL, 1, N'HOME')
INSERT [dbo].[CMSPage] ([PageId], [ParentId], [LivePageVersionId], [Reference]) VALUES (2, 1, 2, N'LOGIN')
SET IDENTITY_INSERT [dbo].[CMSPage] OFF

INSERT [dbo].[User] ([UserId], [Password], [Email], [Surname], [FirstName], [IsActive]) VALUES (N'admin', N'21232f297a57a5a743894a0e4a801fc3', NULL, NULL, NULL, 1)

INSERT [dbo].[Role] ([RoleId], [Name], [IsDefault]) VALUES (N'Admin', N'Admin', 0)
INSERT [dbo].[Role] ([RoleId], [Name], [IsDefault]) VALUES (N'Editor', N'Editor', 0)
INSERT [dbo].[Role] ([RoleId], [Name], [IsDefault]) VALUES (N'Guest', N'Guest', 1)
INSERT [dbo].[Role] ([RoleId], [Name], [IsDefault]) VALUES (N'SuperAdmin', N'Super Admin', 0)
INSERT [dbo].[Role] ([RoleId], [Name], [IsDefault]) VALUES (N'User', N'User', 0)

SET IDENTITY_INSERT [dbo].[Url] ON
INSERT [dbo].[Url] ([UrlId], [PageId], [LanguageId], [PageUrl]) VALUES (1, 1, N'en', N'')
INSERT [dbo].[Url] ([UrlId], [PageId], [LanguageId], [PageUrl]) VALUES (2, 2, N'en', N'login')
SET IDENTITY_INSERT [dbo].[Url] OFF

SET IDENTITY_INSERT [dbo].[CMSPageVersion] ON
INSERT [dbo].[CMSPageVersion] ([PageVersionId], [PageId], [LanguageId], [Order], [UserId], [IsLive], [DateCreated], [Title], [Template], [Keywords], [Description], [NoFollow], [Tags], [Definition]) VALUES (2, 2, N'en', 1, NULL, 1, CAST(0x00009BDA014ADD7A AS DateTime), N'Login', N'Default', NULL, NULL, 1, N'hidden', N'{"Areas":[{"Modules":[],"Id":"footer"},{"Modules":[],"Id":"menucontainer"},{"Modules":[{"ModuleType":"OpenQuarters.WebQuarters.Modules.Core.LoginModule","ModuleJSON":"{}","JQueryEditorName":"cmsModuleEditor","ModuleName":"Login Module","ModuleNameClassSafe":"loginModule","UniqueID":"755000c6_6008_4050_99cc_8ac13c208a1f","IsInherited":false}],"Id":"main"},{"Modules":[],"Id":"logindisplay"}]}')
INSERT [dbo].[CMSPageVersion] ([PageVersionId], [PageId], [LanguageId], [Order], [UserId], [IsLive], [DateCreated], [Title], [Template], [Keywords], [Description], [NoFollow], [Tags], [Definition]) VALUES (1, 1, N'en', 0, NULL, 1, CAST(0x00009BE200A50832 AS DateTime), N'Home', N'Home', N'keywords go here', N'description goes here', 0, N'', N'{"Areas":[{"Modules":[{"ModuleType":"OpenQuarters.WebQuarters.Modules.Core.LoginModule","ModuleJSON":"{\"Display_Log_Out_as\":1, \"Display_Form\":false, \"ModuleId\":\"40141ec1_9dd9_47f2_8d5b_4063ab6409cb\"}","JQueryEditorName":"cmsModuleEditor","ModuleName":"Login Module","ModuleNameClassSafe":"loginModule","UniqueID":"c02ad955_00fe_4d7f_a2c9_54f5e8caf565","IsInherited":false}],"Id":"logindisplay"},{"Modules":[{"ModuleType":"OpenQuarters.WebQuarters.Modules.Core.NavigationModule","ModuleJSON":"{\"Start_Page\":\"1\", \"Start_Page_at_2nd_Level\":\"true\", \"Flatten_Hierarchy\":\"false\", \"Include_Tags\":\"\", \"Exclude_Tags\":\"\", \"Maximum_levels\":\"1\", \"ModuleId\":\"b7d25273_209e_4ac6_9882_aaa8b5fa6d2c\"}","JQueryEditorName":"cmsModuleEditor, cmsModuleEditor_Navigation","ModuleName":"Navigation Module","ModuleNameClassSafe":"navigationModule","UniqueID":"7ff742c5_a708_4e0c_83ce_954d2549a186","IsInherited":false}],"Id":"menucontainer"},{"Modules":[{"ModuleType":"OpenQuarters.WebQuarters.Modules.Core.ContentModule","ModuleJSON":"{\"Content\":\"<h2>Welcome to WebQuarters</h2>\\n    <p>\\n        To learn more about WebQuarters visit <a href=\\\"http://www.openquarters.org\\\" title=\\\"OpenQuarters\\\">http://www.openquarters.org</a>.\\n    </p>\", \"Template\":\"\", \"ModuleId\":\"e12c9a37_2190_42f2_842e_d4f2b0881734\"}","JQueryEditorName":"cmsModuleEditor, cmsContentModuleEditor","ModuleName":"Page Content","ModuleNameClassSafe":"pageContent","UniqueID":"4192862f_fa6b_42c5_a646_42891a131ae8","IsInherited":false}],"Id":"main"},{"Modules":[],"Id":"footer"}]}')
SET IDENTITY_INSERT [dbo].[CMSPageVersion] OFF

INSERT [dbo].[UserRole] ([UserId], [RoleId]) VALUES (N'admin', N'SuperAdmin')

INSERT [dbo].[Permission] ([UserId], [RoleId], [Name], [Value]) VALUES (NULL, N'SuperAdmin', N'Admin.AddWorkflowComment', N'')
INSERT [dbo].[Permission] ([UserId], [RoleId], [Name], [Value]) VALUES (NULL, N'Guest', N'CMSPage.View', N'1')
INSERT [dbo].[Permission] ([UserId], [RoleId], [Name], [Value]) VALUES (NULL, N'User', N'CMSPage.View', N'1')
INSERT [dbo].[Permission] ([UserId], [RoleId], [Name], [Value]) VALUES (NULL, N'Editor', N'CMSPage.View', N'1')
INSERT [dbo].[Permission] ([UserId], [RoleId], [Name], [Value]) VALUES (NULL, N'Editor', N'CMSPage.Edit', N'1')
INSERT [dbo].[Permission] ([UserId], [RoleId], [Name], [Value]) VALUES (NULL, N'Editor', N'CMSPage.Create', N'1')
INSERT [dbo].[Permission] ([UserId], [RoleId], [Name], [Value]) VALUES (NULL, N'Editor', N'CMSPage.Delete', N'1')
INSERT [dbo].[Permission] ([UserId], [RoleId], [Name], [Value]) VALUES (NULL, N'Admin', N'CMSPage.View', N'1')
INSERT [dbo].[Permission] ([UserId], [RoleId], [Name], [Value]) VALUES (NULL, N'Admin', N'CMSPage.Edit', N'1')
INSERT [dbo].[Permission] ([UserId], [RoleId], [Name], [Value]) VALUES (NULL, N'Admin', N'CMSPage.Create', N'1')
INSERT [dbo].[Permission] ([UserId], [RoleId], [Name], [Value]) VALUES (NULL, N'Admin', N'CMSPage.Delete', N'1')
INSERT [dbo].[Permission] ([UserId], [RoleId], [Name], [Value]) VALUES (NULL, N'Admin', N'CMSPage.Approve', N'1')
INSERT [dbo].[Permission] ([UserId], [RoleId], [Name], [Value]) VALUES (NULL, N'Admin', N'CMSPage.View', N'1')
INSERT [dbo].[Permission] ([UserId], [RoleId], [Name], [Value]) VALUES (NULL, N'Admin', N'CMSPage.Edit', N'1')
INSERT [dbo].[Permission] ([UserId], [RoleId], [Name], [Value]) VALUES (NULL, N'Admin', N'CMSPage.Create', N'1')
INSERT [dbo].[Permission] ([UserId], [RoleId], [Name], [Value]) VALUES (NULL, N'Admin', N'CMSPage.Delete', N'1')
INSERT [dbo].[Permission] ([UserId], [RoleId], [Name], [Value]) VALUES (NULL, N'Admin', N'CMSPage.Approve', N'1')
INSERT [dbo].[Permission] ([UserId], [RoleId], [Name], [Value]) VALUES (NULL, N'SuperAdmin', N'CMSPage.View', N'1')
INSERT [dbo].[Permission] ([UserId], [RoleId], [Name], [Value]) VALUES (NULL, N'SuperAdmin', N'CMSPage.Edit', N'1')
INSERT [dbo].[Permission] ([UserId], [RoleId], [Name], [Value]) VALUES (NULL, N'SuperAdmin', N'CMSPage.Create', N'1')
INSERT [dbo].[Permission] ([UserId], [RoleId], [Name], [Value]) VALUES (NULL, N'SuperAdmin', N'CMSPage.Delete', N'1')
INSERT [dbo].[Permission] ([UserId], [RoleId], [Name], [Value]) VALUES (NULL, N'SuperAdmin', N'CMSPage.Approve', N'1')
INSERT [dbo].[Permission] ([UserId], [RoleId], [Name], [Value]) VALUES (NULL, N'Guest', N'CMSPage.View', N'2')
INSERT [dbo].[Permission] ([UserId], [RoleId], [Name], [Value]) VALUES (NULL, N'User', N'CMSPage.View', N'2')
INSERT [dbo].[Permission] ([UserId], [RoleId], [Name], [Value]) VALUES (NULL, N'Editor', N'CMSPage.View', N'2')
INSERT [dbo].[Permission] ([UserId], [RoleId], [Name], [Value]) VALUES (NULL, N'Editor', N'CMSPage.Edit', N'2')
INSERT [dbo].[Permission] ([UserId], [RoleId], [Name], [Value]) VALUES (NULL, N'Editor', N'CMSPage.Create', N'2')
INSERT [dbo].[Permission] ([UserId], [RoleId], [Name], [Value]) VALUES (NULL, N'Editor', N'CMSPage.Delete', N'2')
INSERT [dbo].[Permission] ([UserId], [RoleId], [Name], [Value]) VALUES (NULL, N'Admin', N'CMSPage.View', N'2')
INSERT [dbo].[Permission] ([UserId], [RoleId], [Name], [Value]) VALUES (NULL, N'Admin', N'CMSPage.Edit', N'2')
INSERT [dbo].[Permission] ([UserId], [RoleId], [Name], [Value]) VALUES (NULL, N'Admin', N'CMSPage.Create', N'2')
INSERT [dbo].[Permission] ([UserId], [RoleId], [Name], [Value]) VALUES (NULL, N'Admin', N'CMSPage.Delete', N'2')
INSERT [dbo].[Permission] ([UserId], [RoleId], [Name], [Value]) VALUES (NULL, N'Admin', N'CMSPage.Approve', N'2')
INSERT [dbo].[Permission] ([UserId], [RoleId], [Name], [Value]) VALUES (NULL, N'Admin', N'CMSPage.View', N'2')
INSERT [dbo].[Permission] ([UserId], [RoleId], [Name], [Value]) VALUES (NULL, N'Admin', N'CMSPage.Edit', N'2')
INSERT [dbo].[Permission] ([UserId], [RoleId], [Name], [Value]) VALUES (NULL, N'Admin', N'CMSPage.Create', N'2')
INSERT [dbo].[Permission] ([UserId], [RoleId], [Name], [Value]) VALUES (NULL, N'Admin', N'CMSPage.Delete', N'2')
INSERT [dbo].[Permission] ([UserId], [RoleId], [Name], [Value]) VALUES (NULL, N'Admin', N'CMSPage.Approve', N'2')
INSERT [dbo].[Permission] ([UserId], [RoleId], [Name], [Value]) VALUES (NULL, N'SuperAdmin', N'CMSPage.View', N'2')
INSERT [dbo].[Permission] ([UserId], [RoleId], [Name], [Value]) VALUES (NULL, N'SuperAdmin', N'CMSPage.Edit', N'2')
INSERT [dbo].[Permission] ([UserId], [RoleId], [Name], [Value]) VALUES (NULL, N'SuperAdmin', N'CMSPage.Create', N'2')
INSERT [dbo].[Permission] ([UserId], [RoleId], [Name], [Value]) VALUES (NULL, N'SuperAdmin', N'CMSPage.Delete', N'2')
INSERT [dbo].[Permission] ([UserId], [RoleId], [Name], [Value]) VALUES (NULL, N'SuperAdmin', N'CMSPage.Approve', N'2')
INSERT [dbo].[Permission] ([UserId], [RoleId], [Name], [Value]) VALUES (NULL, N'Guest', N'CMSPage.View', N'2')
INSERT [dbo].[Permission] ([UserId], [RoleId], [Name], [Value]) VALUES (NULL, N'Guest', N'CMSPage.View', N'2')
INSERT [dbo].[Permission] ([UserId], [RoleId], [Name], [Value]) VALUES (NULL, N'SuperAdmin', N'Module.CreateInstance', N'OpenQuarters.WebQuarters.Modules.Core.ContentModule')
INSERT [dbo].[Permission] ([UserId], [RoleId], [Name], [Value]) VALUES (NULL, N'SuperAdmin', N'Module.CreateInstance', N'OpenQuarters.WebQuarters.Modules.Core.LoginModule')
INSERT [dbo].[Permission] ([UserId], [RoleId], [Name], [Value]) VALUES (NULL, N'SuperAdmin', N'CMSPage.Order', N'')
INSERT [dbo].[Permission] ([UserId], [RoleId], [Name], [Value]) VALUES (NULL, N'Admin', N'CMSPage.Order', N'')
